package org.wanho.servlet;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/hello")
public class HelloServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("接收到客户端的请求...................");

        // 响应的内容类型
        resp.setContentType("text/html; charset=utf8");

        // 获取输出流
        PrintWriter out = resp.getWriter();
        out.print("<h2 style='color:red;'>Hello Servlet</h2>");
        out.close();
    }
}
